package com.atliuzu.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.fastjson.JSONObject;
import com.atliuzu.common.GmallConfig;


import java.sql.Connection;
import java.util.List;

/**
 * @Author Administrator
 * @Time 2022-08-21-11:27
 */
public class DimUtil {
    //向redis中写数据
    public static JSONObject getDimInfo( Connection connection, String tableName, String key) throws Exception {

        //从hbase中查找
        //拼接SQL
        String sql = "select * from " + GmallConfig.HBASE_SCHEMA + "." + tableName + " where id= '" + key + "'";

        //查询
        List<JSONObject> queryList = JdbcUtil.queryList(connection, sql, JSONObject.class, false);

        //id为主键，查询结果数据只有一条，所以要get(0)
        return queryList.get(0);

    }


    public static void main(String[] args) throws Exception {

        DruidDataSource dataSource = DruidDSUtil.createDataSource();
        DruidPooledConnection connection = dataSource.getConnection();



        long start = System.currentTimeMillis();
        System.out.println(getDimInfo(connection, "DIM_COURSE_INFO", "39")); //148 148 143 148 140
        long end = System.currentTimeMillis();

        System.out.println(getDimInfo(connection, "DIM_COURSE_INFO", "39")); //10 8 8 9   0 1 1 1 1
        long end2 = System.currentTimeMillis();

        System.out.println(end - start);
        System.out.println(end2 - end);

        connection.close();
        dataSource.close();
    }

}
